package com.reggie.category.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.reggie.category.entity.Category;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryDao extends BaseMapper<Category> {

    /**
     * 判断category的id有没有绑定菜品，如果有就不能删除
     *
     * @param id
     * @return
     */
    @Select("select count(*) from dish where category_id = #{id}")
    int selectByDishId(Long id);

    @Select("select count(*) from setmeal where category_id = #{id}")
    int selectBySetmealId(Long id);

    @Select("select * from category order by sort desc, update_time desc")
    List<Category> selectByType();
}
